package com.dhq.topic;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * 发布订阅的模式 没有消费者 消息就删除掉了
 */
public class Test {
    public static void main(String[] args) throws JMSException {
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
        Connection connection = connectionFactory.createConnection();

        connection.start();
        //创建session
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        Topic topic = session.createTopic("频道1");

        MessageProducer producer = session.createProducer(topic);

        TextMessage textMessage = session.createTextMessage("topic message1~");

        producer.send(textMessage);

        producer.close();
        session.close();
        connection.close();
    }
}
